#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QQmlApplicationEngine>
#include <QWebEngineView>
#include <QStackedLayout>
#include <QWebChannel>
#include "bridge.h"

MainWindow::MainWindow(QWidget *parent) :
	QMainWindow(parent),
	ui(new Ui::MainWindow)
{
	ui->setupUi(this);

	m_view = new QWebEngineView(this);
	QWebChannel *channel = new QWebChannel(this);
	channel->registerObject("bridge", (QObject*)bridge::instance());
	m_view->page()->setWebChannel(channel);
    // m_view->page()->load(QUrl("http://192.168.230.1:8889/"));
    // m_view->page()->load(QUrl(QString("file:///D:/Project/qWebEngineView-Nodejs/monitor/views/engine.html")));


    // m_view->page()->load(QUrl("http://localhost:5173/"));
    m_view->page()->load(QUrl("https://demo.gin-vue-admin.com/#/login")); // 访问 gin-vue 官网

	ui->viewLayout->addWidget(m_view);
	connect(ui->pbAlert, &QPushButton::clicked, [this]() {
		m_view->page()->runJavaScript("showAlert()");
	});

}

MainWindow::~MainWindow()
{
	delete ui;
}
